<template>
  <div>
    <el-row :gutter="20">
        <el-col :span="8">
          <!-- 搜索 clearable:清空数据，@clear:查询数据-->
          <el-input
      v-model="xx"
      placeholder="请输入学号"
    ><template #append>
        <el-button @click="getls()"><el-icon><Search /></el-icon></el-button>
      </template>
    </el-input></el-col>
        <!--------------------------- 添加用户 -------------------------------->
        <el-col :span="4"
          ><el-button color="#626aef" type="primary" @click="addDialogVisible = true">添加用户</el-button>
        </el-col>
        <el-dialog
          title="添加用户(请填写完整)"
          v-model="addDialogVisible"
          width="50%"
        >
          <!-- 添加用户内容底部区域 -->
          <el-form label-width="70px">

            <el-form-item label="学号">
              <el-input v-model="sid" placeholder="Please input"></el-input>
            </el-form-item>

            <el-form-item label="人格简称">
              <el-input v-model="mal" placeholder="Please input"></el-input>
            </el-form-item>

            <el-form-item label="测试时间">
              <el-input v-model="date" placeholder="Please input"></el-input>
            </el-form-item>

          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="addDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="inserttestlog()">确 定</el-button>
          </span>
        </el-dialog>

      </el-row>

      <el-table :data="user" border stripe>
        <el-table-column type="index"></el-table-column>

        <el-tableColumn label="学号" prop="sid"></el-tableColumn>
        <el-tableColumn label="人格简称" prop="mal"></el-tableColumn>
        <el-tableColumn label="测试时间" prop="date"></el-tableColumn>

        <el-tableColumn label="操作" width="180px"> 
          <!-------------------------------- 修改用户按钮 ---------------------------------->
          <el-button type="primary" size="mini" @click="editDialogVisible = true"><el-icon><Edit /></el-icon></el-button>
          
          <!------------------------------- 删除用户按钮 ------------------------------>
          <el-button
            type="danger"
            size="mini"
            @click="deleteDialogVisible = true"
          ><el-icon><Delete /></el-icon></el-button>
          <!---------------分配角色按钮,tooltip:提示框,enterable:自动隐藏 -------------->



        </el-tableColumn>
      </el-table>
      <el-dialog
          title="修改用户资料"
          v-model="editDialogVisible"
          width="50%"
        >
          <!-- 添加用户内容底部区域 -->
          <el-form label-width="70px">

            <el-form-item label="学号">
              <el-input v-model="updatesid" placeholder="您要修改的该学生学号"></el-input>
            </el-form-item>

            <el-form-item label="人格简称">
              <el-input v-model="updatemal" placeholder="Please input"></el-input>
            </el-form-item>

            <el-form-item label="测试时间">
              <el-input v-model="updatedate" placeholder="Please input"></el-input>
            </el-form-item>

          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="editDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="updatetestlog()">确 定</el-button>
          </span>
        </el-dialog>


        <el-dialog
          title="删除用户资料"
          v-model="deleteDialogVisible"
          width="50%"
        >
          <!-- 添加用户内容底部区域 -->
          <el-form label-width="70px">

            <el-form-item label="学号">
              <el-input v-model="deletesid" placeholder="Please input"></el-input>
            </el-form-item>

          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="deleteDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="deletetestlog()">确 定</el-button>
          </span>
        </el-dialog>
  </div>
</template>

<script>
import { h } from 'vue'
import { ElNotification } from 'element-plus'
import { ref } from 'vue'
export default {
  data() {
    return {
      sid:ref(''),
      mal:ref(''),
      date:ref(''),

      updatesid:ref(''),
      updatemal:ref(''),
      updatedate:ref(''),

      deletesid:ref(''),

      addDialogVisible: false,
      editDialogVisible: false,
      deleteDialogVisible: false,
      user:[],
      xx:ref(''),
    }
  },
  created() {
    // this.getls()
  },
  methods: {
    // 获取用户列表数据（getUserList）
    getls() {
      const that = this
      this.$axios.get('/gettestlog', { params: { xx: this.xx } }).then(function (response) {
        
        if(response['data']){
          that.user.push(response['data'])
        }
      })
    },
    addDialogClosed() {
      this.$refs.addUserFormRef.resetFields()
    },
    editDialogClosed() {
      this.$refs.editUserFormRef.resetFields()
    },
    deleteDialogClosed() {
      this.$refs.editUserFormRef.resetFields()
    },
    inserttestlog() {
      const that = this
      this.$axios.get('/inserttestlog',{params:{
        sid:this.sid,
        mal:this.mal,
        date:this.date,
        }})
      .then(function(response) { 
        console.log("插入成功！");
        ElNotification({
            title: "成功",
            message: h('i', { style: 'color: coral' }, '用户已插入数据库'),
        })
      })
    },
    updatetestlog(){
      const that = this
      this.$axios.get('/updatetestlog',{params:{
        sid:this.updatesid,
        mal:this.updatemal,
        date:this.updatedate,
        }})
      .then(function(response) { 
        console.log("修改成功！");
        ElNotification({
            title: "成功",
            message: h('i', { style: 'color: coral' }, '用户已插入数据库'),
        })
      })
    },
    deletetestlog(){
      const that = this
      this.$axios.get('/deletetestlog',{params:{
        sid:this.deletesid,
        }})
      .then(function(response) { 
        console.log("删除成功！");
        ElNotification({
            title: "成功",
            message: h('i', { style: 'color: coral' }, '用户已在数据库删除'),
        })
      })
    }
  },
}
</script>

<style lang="less" scoped></style>

